package com.quectel.util.kit;

import com.quectel.util.client.minio.MinIOClient;
import com.quectel.util.ex.CheckErrorException;

import java.io.File;
import java.io.InputStream;
import java.util.Arrays;

/**
 * 上传帮助类
 *
 * @author: cl
 * @date: 2020-04-15 10:22:00
 */
@Deprecated
public class StorageKit {


    /**
     * @param in
     * @return 可访问的url
     */
    public static String uploadStreamToPublicBucketObtainUrl(InputStream in, String fileName) {
        if (in == null) {
            throw new CheckErrorException("Stream is null");
        }
        return MinIOUtils.putStreamToPublicBucketObtainUrl(MinIOClient.DEFAULT_PUBLIC_BUCKET, in, fileName, false);
    }

    /**
     * @param file
     * @return 可访问的url
     */
    public static String uploadToPublicBucketObtainUrl(File file) {
        if (file == null) {
            throw new CheckErrorException("File is null");
        }
        return MinIOUtils.putObjectToPublicBucketObtainUrl(MinIOClient.DEFAULT_PUBLIC_BUCKET, file, false);
    }

    /**
     * @param file
     * @return 文件标识
     */
    public static String uploadToPrivateBucketObtainObject(File file) {
        if (file == null) {
            throw new CheckErrorException("File is null");
        }
        return MinIOUtils.putObjectToBucketObtainObject(MinIOClient.DEFAULT_PRIVATE_BUCKET, file, false);
    }

    /**
     * @param object 私有仓库返回的id
     * @return 文件流 注意关闭
     */
    public static InputStream getObject(String object) {
        return MinIOUtils.getObject(MinIOClient.DEFAULT_PRIVATE_BUCKET, object);
    }

    /**
     * @param objectOrUrl
     */
    public static int deleteFile(String objectOrUrl) {
        return MinIOUtils.deleteObjects(MinIOClient.DEFAULT_PUBLIC_BUCKET, Arrays.asList(objectOrUrl));
    }

}
